#include "GraphicsTypes.h"

using namespace WebKit;
namespace MiraclePlayer
{

class CanvasElement//: public Element
{
	unsigned long width;
	unsigned long height;
public:
	CanvasRenderingContext2D* getContext(const String& contextId);
	//DOMString toDataURL(const String& type, in any... args);
};

class CanvasRenderingContext2D
{
  // back-reference to the canvas 
  const CanvasElement* m_canvas;

public:
  // state 
  void restore(); // pop state stack and restore state
  void save(); 	  // push state on state stack 
        
  // transformations (default transform is the identity matrix)
  void rotate(float angle);
  void scale(float x, float y);
  void setTransform( float m11, float m12, float m21, float m22, float dx, float dy);
  void transform( float m11, float m12, float m21, float m22, float dx, float dy);
  void translate( float x, float y);
        
  // compositing 
  float globalAlpha; // (default 1.0)
  CompositeOperator globalCompositeOperation; // (default source-over)
        
  // colors and styles 
  Color fillStyle; // (default black)
  Color strokeStyle; // (default black)

  Gradient createLinearGradient( float x0, float y0, float x1, float y1);
  Gradient createRadialGradient( float x0, float y0, float r0, float x1, float y1, float r1);
  Pattern createPattern( HTMLImageElement image, const String& repetition);
  //CanvasPattern createPattern(in HTMLCanvasElement image, in DOMString repetition);
  //CanvasPattern createPattern(in HTMLVideoElement image, in DOMString repetition);

  // line styles 
  LineCap lineCap; // "butt", "round", "square" (default "butt")
  LineCap lineJoin; // "miter", "round", "bevel"  (default "miter")
  float lineWidth; // (default 1)
  float miterLimit; // (default 10)

  // shadows 
  float shadowBlur; // (default 0)
  Color shadowColor; // (default transparent black)
  float shadowOffsetX; // (default 0)
  float shadowOffsetY; // (default 0)

  // rects 
  void clearRect( float x, float y, float w, float h);
  void fillRect( float x, float y, float w, float h);
  void strokeRect( float x, float y, float w, float h);

  // Complex shapes (paths) API 
  void arc( float x, float y, float radius, float startAngle, float endAngle, bool anticlockwise);
  void arcTo( float x1, float y1, float x2, float y2, float radius);
  void beginPath();
  void bezierCurveTo( float cp1x, float cp1y, float cp2x, float cp2y, float x, float y);
  void clip();
  void closePath();
  void fill();
  void lineTo( float x, float y);
  void moveTo( float x, float y);
  void quadraticCurveTo( float cpx, float cpy, float x, float y);
  void rect( float x, float y, float w, float h);
  void stroke();
  bool isPointInPath( float x, float y);

  // text 
  String font; // (default 10px sans-serif)
  TextAlign textAlign; // "start", "end", "left", "right", "center" (default: "start")
  TextBaseline textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic")

  void fillText(const String& text, float x, float y, float maxWidth);
  TextMetrics measureText(const String& text);
  void strokeText(const String& text, float x, float y, float maxWidth);

  // drawing images 
  void drawImage(in HTMLImageElement image, float dx, float dy, float dw, float dh);
  void drawImage(in HTMLImageElement image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh);
  //void drawImage(in HTMLCanvasElement image, in float dx, in float dy, optional in float dw, in float dh);
  //void drawImage(in HTMLCanvasElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh);
  //void drawImage(in HTMLVideoElement image, in float dx, in float dy, optional in float dw, in float dh);
  //void drawImage(in HTMLVideoElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh);

  // pixel manipulation
  ImageData createImageData( float sw, float sh);
  ImageData createImageData( ImageData imagedata);
  ImageData getImageData( float sx, float sy, float sw, float sh);
  void putImageData( ImageData imagedata, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight);
};

}